//
//  HZL_headerScrollWebViewController.m
//  B_Project
//
//  Created by 胡佳俊 on 15/11/28.
//  Copyright © 2015年 HZL. All rights reserved.
//

#import "HZL_headerScrollWebViewController.h"

@interface HZL_headerScrollWebViewController ()<UIWebViewDelegate>
@property (nonatomic, retain)UIWebView *WebView;
@property (nonatomic, retain)UIActivityIndicatorView *activity;
@end

@implementation HZL_headerScrollWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self createWebView];
    
    [self createActivity];
}
#pragma mark - 创建webView
- (void)createWebView
{
    self.WebView = [[UIWebView alloc]initWithFrame:CGRectMake(0, -20, VIEW_WIDTH, VIEW_HEIGHT + 20)];
    self.WebView.delegate = self;
    self.WebView.backgroundColor = [UIColor whiteColor];
    
    
    UIView *vi = [[UIView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, 20)];
    vi.backgroundColor = [UIColor whiteColor];
    [self.WebView addSubview:vi];
    
    NSURLRequest *request = [[NSURLRequest alloc]initWithURL:[NSURL URLWithString:self.urlStr]];
    [self.WebView loadRequest:request];
    
    [self.view addSubview:self.WebView];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setFrame:CGRectMake(10, 40, 30, 30)];
    btn.backgroundColor = [UIColor clearColor];
    [self.WebView addSubview:btn];
    [btn setImage:[UIImage imageNamed:@"iconfont-xiangzuojiantou@3x"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(go) forControlEvents:UIControlEventTouchUpInside];
    
}
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = YES;
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;
    self.tabBarController.tabBar.hidden = NO;
}

- (void)go
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)createActivity
{
    self.activity = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    self.activity.color = [UIColor colorWithRed:0.18 green:0.63 blue:0.68 alpha:1];
    self.activity.center = self.view.center;
    [self.view addSubview:self.activity];
    
}

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    [self.activity startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [self.activity stopAnimating];
    CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] floatValue];
    self.WebView.scrollView.contentSize = CGSizeMake(self.view.frame.size.width, height);
}


- (void)webView:(UIWebView *)webView  didFailLoadWithError:(NSError *)error
{
    NSLog(@"错误");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
